﻿using System;
using System.Linq;
using Shell.PocoDot;

namespace Shell.DomainDot
{
    public class WithAll<TPocoDot> : IDisposable
        where TPocoDot : PocoDotBase
    {
        private bool disposed;

        public WithAll(IDataContext<TPocoDot> repository)
        {
            this.Repository = repository;
        }

        protected IDataContext<TPocoDot> Repository { get; private set; }


        public IQueryable<TPocoDot> Instances
        {
            get
            {
                return this.Repository.Read();
            }
        }

        public TPocoDot Create()
        {
            return this.Repository.Create();
        }

        public void Delete(Guid key)
        {
            this.Repository.Delete(key);
        }

        public int Submit()
        {
            return this.Repository.Submit();
        }

        public void Dispose()
        {
            this.Dispose(true);
            GC.SuppressFinalize(this);
        }

        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (!this.disposed)
                {
                    this.Repository = null;
                }
                this.disposed = true;
            }
        }
    }
}
